/**
 * 2006-9-12 15:23:04
 * VeryftpInitialFilter.java
 */
package org.lilystudio.veryftp.common;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author Samson
 * 
 */
public class VeryftpInitialFilter implements Filter {

	private static Log log = LogFactory.getLog(VeryftpInitialFilter.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
	 */
	public void init(FilterConfig filterConfig) throws ServletException {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
	 *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) throws IOException, ServletException {
		initConstant();
		initProperties();
		filterChain.doFilter(request, response);
	}

	protected void initConstant() {
		// init some constant here.
	}

	protected void initProperties() {
		Properties properties = System.getProperties();
		String veryftpBaseDir = properties.getProperty("catalina.home");
		veryftpBaseDir += "/webapps/" + Constant.PROJECT_NAME + "/";
		System.getProperties().setProperty(Constant.PROJECT_BASEDIR,
				veryftpBaseDir);
		log.info("Project Base Directory : " + veryftpBaseDir);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#destroy()
	 */
	public void destroy() {
	}

}
